<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-07-31
 * Time: 17:00
 */
namespace app\index\controller;
use app\index\model\Staff;
class Settr{

    //字段获取器:get字段名Attr( )
    public function index(){

        //获取表中id=1004的记录
        $staff = Staff::get(1009);

        //获取数据对象原始信息
        $before = $staff -> getData('dept');
        echo '1. 没用获取器方法之前 dept :'.$before;

        echo '<br />';

        //获取经获取器转换之后的信息
//        $after = $staff ->getAttr('dept');
        $after = $staff -> dept ;

        echo '2. 调用获取器方法之后 dept: '.$after;
    }


    //字段修改器:set字段名Attr( )
    public function index1(){

        //获取id=1001的数据
        $staff = Staff::get(1005);

        //修改当前记录的sex字段值:1
        //此时会触发模型类中的修改器:setSexAttr()
        $staff -> setAttr('sex',1);

        //写入表中
        $staff ->allowField(true)->save();

        //查看当前数据对象
        dump($staff->getData());
    }
    public function index3(){
        //获取主键为1001的记录信息
        $a = Staff::get(1035)->getData('create_time');
        $b = date('Y-m-d H:i:s', $a);
        dump(Staff::get(1035)->getData('create_time'));
        dump($b);
    }

}